function verifyRegister(){
	if(document.getElementById("chk").checked){
		if(!verifyPassword() || !verifyIdCard()){
			return false;
		}
		return true;
	} else {
		alert("กรุณายืนยันข้อมูล");
		return false;
	}
}

function verifyOldPassword(){
	if(frm.oldpassword.value != frm.repassword.value){
		document.getElementById('p_err').setAttribute("class","alert alert-error");
		document.getElementById('p_err').innerHTML = "รหัสผ่านไม่ตรงกัน";
		return false;
	} else {
		document.getElementById('p_err').setAttribute("class","alert alert-success");
		document.getElementById('p_err').innerHTML = "รหัสผ่านถูกต้อง";
		return true;
	}
}
function verifyPassword(){
	if(frm.password.value != frm.repassword.value){
		document.getElementById('p_err').setAttribute("class","alert alert-error");
		document.getElementById('p_err').innerHTML = "รหัสผ่านไม่ตรงกัน";
		return false;
	} else {
		document.getElementById('p_err').setAttribute("class","alert alert-success");
		document.getElementById('p_err').innerHTML = "รหัสผ่านถูกต้อง";
		return true;
	}
}

function verifyIdCard(){
	if(frm.idcard.value.length != 13){
		document.getElementById('i_err').setAttribute("class","alert alert-error");
		document.getElementById('i_err').innerHTML = "หมายเลขบัตรประชาชนต้องครบ 13 หลัก";
		return false;
	} else {
		if(!verifyId(frm.idcard.value)){
			document.getElementById('i_err').setAttribute("class","alert alert-error");
			document.getElementById('i_err').innerHTML = "หมายเลขบัตรประชาชนไม่ถูกต้อง";
			return false;
		} else {
			document.getElementById('i_err').setAttribute("class","alert alert-success");
			document.getElementById('i_err').innerHTML = "หมายเลขบัตรประชาชนถูกต้อง";
			return true;
		}
	}
}
function verifyId(str){
	var vr = str.charAt(str.length-1);
	var sum = 0;
	var num = 13;
	for ( var i = 0; i < str.length-1; i++) {
		sum += (str.charAt(i)*num--);
	}
	var total = ""+(11-(sum%11));
	if(total.length == 2){
		total = total.charAt(1);
	}
	if(total != vr){
		return false;
	}
	return true;
}
